package zhangjiale;

import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;

public class DoubleColorBall {
    public static void main(String[] args) {
        int[] winningNumber = new int[7];
        Set<Integer> redNumbers = new HashSet<>();

        //红色球
        while (redNumbers.size() < 7) {
            Random Number1 = new Random();
            int redNumber = Number1.nextInt(33) + 1;
            redNumbers.add(redNumber);
        }

        //存入
        int index = 0;
        for (int number : redNumbers) {
            winningNumber[index++] = number;
        }

        //蓝色球
        Random Number2 = new Random();
        int blueNumber = Number2.nextInt(16) + 1;
        winningNumber[6] = blueNumber;

        //输入投注号码
        int[] bettingNumber = new int[7];
        Scanner scanner = new Scanner(System.in);
        //输入红色号码
        for (int i = 0; i < bettingNumber.length - 1; i++){
            System.out.println("请输入第" + (i + 1) +"个红色球号码，输入任意一个范围1-33的数字（不重复）：");
            int red = scanner.nextInt();
            //判断输入是否合理
            if (red < 1 || red > 33){
                System.out.println("您输入的号码不规范，请重新输入！");
                i--;
                continue;
            }

            //判断是否重复
            boolean isDuplicate = false;
            for (int num : bettingNumber) {
                if (num == red) {
                    isDuplicate = true;
                    break;
                }
            }
            if (isDuplicate) {
                System.out.println("数字 " + red + "已重复，请重新输入！");
                i--;
                continue;
            }

            bettingNumber[i] = red;
        }

        //输入蓝色号码
        while (true) {
            System.out.println("请输入蓝色球号码，输入任意一个范围1-16的数字（不重复）：");
            int blue = scanner.nextInt();
            //判断输入是否合理
            if (blue < 1 || blue > 16){
                System.out.println("您输入的号码不规范，请重新输入！");
            }else {
                bettingNumber[bettingNumber.length - 1] = blue;
                break;
            }
        }

        System.out.print("中奖号码为：");
        for (int j = 0; j < 7; j++){
            System.out.print(winningNumber[j] + "  ");
        }
        System.out.print("\n");

        System.out.print("您投注的号码为：");
        for (int num : bettingNumber){
            System.out.print(num + "  ");
        }
        System.out.println("\n");

        //比较命中球数
        int redCount = 0;
        int blueCount = 0;
        for (int i = 0; i < winningNumber.length - 1; i++){
            if (winningNumber[i] == bettingNumber[i]){
                redCount++;
            }
        }
        if (winningNumber[winningNumber.length - 1] ==  bettingNumber[bettingNumber.length - 1]) {
            blueCount = 1;
        }
//        System.out.println(redCount + blueCount);

        //输出中奖结果
        if (redCount <= 2 && blueCount > 0){
            System.out.println("你命中了" + redCount + "红色球号码，" + blueCount + "个蓝色球号码。");
            System.out.println("恭喜你，你中了六等奖，可获得5元奖金！");
        } else if (redCount + blueCount == 4 ) {
            System.out.println("你命中了" + redCount + "红色球号码，" + blueCount + "个蓝色球号码。");
            System.out.println("恭喜你，你中了五等奖，可获得10元奖金！");
        } else if (redCount + blueCount == 5) {
            System.out.println("你命中了" + redCount + "红色球号码，" + blueCount + "个蓝色球号码。");
            System.out.println("恭喜你，你中了四等奖，可获得200元奖金！");
        } else if (redCount + blueCount == 6) {
            System.out.println("你命中了" + redCount + "红色球号码，" + blueCount + "个蓝色球号码。");
            System.out.println("恭喜你，你中了三等奖，获得3000元奖金！");
        } else if (redCount == 6 && blueCount == 0) {
            System.out.println("你命中了" + redCount + "红色球号码，" + blueCount + "个蓝色球号码。");
            System.out.println("恭喜你，你中了二等奖，最高可获得500万元奖金！");
        } else if (redCount + blueCount == 7) {
            System.out.println("你命中了" + redCount + "红色球号码，" + blueCount + "个蓝色球号码。");
            System.out.println("恭喜你，你中了一等奖，最高可获得1000万元奖金！");
        }else {
            System.out.println("你命中了" + redCount + "红色球号码，" + blueCount + "个蓝色球号码。");
            System.out.println("很遗憾，你未中奖！");
        }
        System.out.println("软件2301-张佳乐");


    }
}
